﻿using System;
using System.Security.Cryptography;
using BLL.Security;

namespace BLL.Services.Users
{
    public class User
    {
        public int UserId { get; set; }

        public string Email { get; set; }

        internal byte[] PasswordHash { get; set; }

        public string Login { get; set; }

        public DateTime RegistrationDate { get; set; }

        internal byte[] Salt { get; set; }

        public UserStatus Status { get; set; }

        /// <summary>
        /// Sets the password for this user.
        /// </summary>
        /// <param name="newPassword">The new password.</param>
        public void SetPassword(string newPassword)
        {
            Salt = new byte[8];
            (new RNGCryptoServiceProvider()).GetNonZeroBytes(Salt);

            PasswordHash = Cryptographer.GenerateHash(newPassword, Salt);
        }
    }
}
